import request from "@/service/request";
import requestAly from "@/service/requestAly";
import { PromisePageResponse, PromiseResponse } from "@/service/api/type.ts";
import { SchoolSiteArticleVo,SysDictDataVo,SysOrganizationVo } from "@/service/api/school/news/types.ts";


// 获取凭证
const getOssAuth = (query: any) => {
  return request({
    url: "/system/oss/uploadAuth",
    method: "get",
    params: query,
  });
};

// 文件上传到OSS
const postToOSS = (File: any) => {
  return requestAly({
    url: ``,
    method: "post",
    data: File,
  });
};

/**
 * 新增学校新闻
 * @param query
 */
const addSchoolNews = (query: any): PromiseResponse<any> => {
  return request({
    url: "/school/article",
    method: "post",
    data: query,
  });
};

/**
 * 获取学校新闻列表
 * @param query
 */
const getSchoolNewsList = (
  query: any,
): PromisePageResponse<SchoolSiteArticleVo> => {
  return request({
    url: "/school/article/list",
    method: "get",
    params: query,
  });
};

/**
 * 获取学校新闻详情
 * @param newsId
 */
const getSchoolNewsDetail = (
  newsId: any,
): PromiseResponse<SchoolSiteArticleVo> => {
  return request({
    url: `/school/article/${newsId}`,
    method: "get",
  });
};

/**
 * 修改学校新闻
 * @param query
 */
const updateSchoolNews = (query: any): PromiseResponse<any> => {
  return request({
    url: "/school/article/edit",
    method: "put",
    data: query,
  });
};

/**
 * 删除学校新闻
 * @param newsId
 */
const deleteSchoolNews = (newsId: string | string[]) => {
  return request({
    url: `/school/article/${newsId}`,
    method: "delete",
  });
};


/**
 * 获取根组织类型
 */
const getRootOrganizationTypeList = (): PromisePageResponse<SysDictDataVo> => {
  return request({
    url: "/system/dict/data/list",
    method: "get",
    params: {
      dictType: "organization_type",
      parentId: 0
    },
  });
};

/**
 * 获取根组织列表
 * @param query
 */
const getRootOrganizationList = (
  query: any,
): PromisePageResponse<SysOrganizationVo> => {
return request({
  url: "/system/organization/list",
  method: "get",
  params: query,
});
};


export {
  getOssAuth,
  postToOSS,
  addSchoolNews,
  getSchoolNewsList,
  getSchoolNewsDetail,
  updateSchoolNews,
  deleteSchoolNews,
  getRootOrganizationTypeList,
  getRootOrganizationList
};
